package com.eshop.config;

import com.eshop.utils.SecurityUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service("el")
public class ElPermissionConfig
{
    public Boolean check(final String... permissions) {
        final List<String> elPermissions = SecurityUtils.getUserDetails().
                getAuthorities().stream().map(GrantedAuthority::getAuthority)
                .collect(Collectors.toList());
        return elPermissions.contains("admin") || Arrays.stream(permissions)
                .anyMatch(elPermissions::contains);
    }
}
